package reflection.utils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA
 * Description:获取类结构的API演示1
 * User:22954
 * Date:2024-04-15
 * Time:12:24
 */
public class API1 {
    public static void main(String[] args) throws ClassNotFoundException {
        Class<?> cls = Class.forName("reflection.utils.B");

        String name = cls.getName();
        System.out.println("全类名:" + name);

        String name1 = cls.getSimpleName();
        System.out.println("简单类名:" + name1);

        Field[] fields = cls.getFields();
        for (Field field : fields) {
            System.out.println("本类及父类public属性:" + field);
        }

        Field[] fields1 = cls.getDeclaredFields();
        for (Field field : fields1) {
            System.out.println("本类所有属性:" + field);
        }

        Method[] methods = cls.getMethods();
        for (Method method : methods) {
            System.out.println("本类及父类public方法:" + method);
        }

        Method[] methods1 = cls.getDeclaredMethods();
        for (Method method : methods1) {
            System.out.println("本类所有方法:" + method);
        }

        Constructor<?>[] constructors = cls.getConstructors();
        for (Constructor<?> constructor : constructors) {
            System.out.println("本类public构造器:" + constructor);
        }

        Constructor<?>[] constructors1 = cls.getDeclaredConstructors();
        for (Constructor<?> constructor : constructors1) {
            System.out.println("本类所有构造器:" + constructor);
        }

        Package clsPackage = cls.getPackage();
        System.out.println("包信息:" + clsPackage);

        Class<?> clsSuperclass = cls.getSuperclass();
        System.out.println("父类信息:" + clsSuperclass);

        Class<?>[] interfaces = cls.getInterfaces();
        for (Class<?> anInterface : interfaces) {
            System.out.println("本类实现接口:" + anInterface);
        }

        Annotation[] annotations = cls.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println("本类注解:" + annotation);
        }
    }
}

interface IA {
}

interface IB {
}

class A {
    public String a1;
    protected int a2;
    private boolean a3;

    public A() {
    }

    A(int a2) {
    }

    public void Am1() {
    }

    private void Am2() {
    }
}

@Deprecated
class B extends A implements IA, IB {
    public String b1;
    protected int b2;
    long b3;
    private boolean b4;

    public B() {
        super();
    }

    private B(int b2) {
    }

    public void Bm1() {
    }

    private boolean Bm2(int b2) {
        return true;
    }
    public static int Bm3(String b1, short k){
        return 1;
    }
}